package org.xbill.DNS;

public final class TTL
{
  public static final long MAX_VALUE = 2147483647L;

  static void check(long paramLong)
  {
    if ((paramLong < 0L) || (paramLong > 2147483647L))
      throw new InvalidTTLException(paramLong);
  }

  public static String format(long paramLong)
  {
    check(paramLong);
    StringBuffer localStringBuffer = new StringBuffer();
    long l1 = paramLong % 60L;
    long l2 = paramLong / 60L;
    long l3 = l2 % 60L;
    long l4 = l2 / 60L;
    long l5 = l4 % 24L;
    long l6 = l4 / 24L;
    long l7 = l6 % 7L;
    long l8 = l6 / 7L;
    if (l8 > 0L)
      localStringBuffer.append(l8 + "W");
    if (l7 > 0L)
      localStringBuffer.append(l7 + "D");
    if (l5 > 0L)
      localStringBuffer.append(l5 + "H");
    if (l3 > 0L)
      localStringBuffer.append(l3 + "M");
    if ((l1 > 0L) || ((l8 == 0L) && (l7 == 0L) && (l5 == 0L) && (l3 == 0L)))
      localStringBuffer.append(l1 + "S");
    return localStringBuffer.toString();
  }

  public static long parse(String paramString, boolean paramBoolean)
  {
    long l4;
    long l7;
    long l8;
    long l9;
    long l10;
    long l11;
    if ((paramString == null) || (paramString.length() == 0) || (!(Character.isDigit(paramString.charAt(0)))))
      throw new NumberFormatException();
    long l1 = 0L;
    long l2 = 0L;
    int i = 0;
    if (i >= paramString.length())
    {
      if (l2 != 0L)
        break label295;
      l11 = l1;
      if (l11 <= -1L)
        break label267;
      throw new NumberFormatException();
    }
    char c = paramString.charAt(i);
    long l3 = l1;
    if (Character.isDigit(c))
    {
      l10 = l1 * 10L + Character.getNumericValue(c);
      if (l10 >= l3)
        break label246;
      throw new NumberFormatException();
    }
    switch (Character.toUpperCase(c))
    {
    default:
      throw new NumberFormatException();
    case 'W':
      l9 = 7L * l1;
      l8 = l9 * 24L;
      l7 = l8 * 60L;
      l4 = l7 * 60L;
    case 'D':
    case 'H':
    case 'M':
    case 'S':
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              label246: long l12;
              while (true)
              {
                long l5 = l4 + l2;
                long l6 = 0L;
                if (l5 > -1L)
                {
                  throw new NumberFormatException();
                  l5 = l2;
                  l6 = l10;
                }
                ++i;
                l1 = l6;
                l2 = l5;
              }
              if ((l11 > 2147483647L) && (paramBoolean))
                label267: l12 = 2147483647L;
              while (true)
              {
                return l12;
                l12 = l11;
              }
              label295: l11 = l2;
            }
            l9 = l1;
          }
          l8 = l1;
        }
        l7 = l1;
      }
      l4 = l1;
    }
  }

  public static long parseTTL(String paramString)
  {
    return parse(paramString, true);
  }
}